<template>
  <basic-container>
    <avue-form :option="option" v-model="form" @submit="handleSubmit"/>
  </basic-container>
</template>

<script>
  import {startDrawingApproval} from "@/api/drawing/drawingapproval";
  import {getUserInfo} from "@/api/system/user";
  import {getDetail} from "@/api/drawing/drawingupload";
  import { Loading } from "element-ui";

  export default {
    data() {
      return {
        btnLoading: false,
        form: {},
        option: {
          group: [
            {
              icon: 'el-icon-info',
              label: '图纸审批基础信息',
              prop: 'group1',
              column: [
                {
                  label: '申请人',
                  prop: 'taskUser',
                  span: 24,
                  disabled: true
                },
                {
                  label: '代号',
                  prop: 'drawingNumber',
                  span: 24,
                  disabled: true
                },
                {
                  label: '名称',
                  prop: 'drawingName',
                  span: 24,
                  disabled: true
                },
                {
                  label: '备注',
                  prop: 'comment',
                  type: 'textarea',
                  span: 24,
                },
              ]
            },
          ],
        }
      }
    },
    created() {
      this.handleWitch()
    },
    methods: {
      handleSubmit() {
        debugger
        this.btnLoading = true;
        const params = {
          processDefinitionId: this.$route.params.processDefinitionId,
          drawingUploadId: this.$route.params.drawingUploadId,
          ...this.form,
        };
        startDrawingApproval(params).then(resp => {
          const data = resp.data;
          if (data.success) {
            this.$message.success(data.msg);
            this.$router.$avueRouter.closeTag();
            // this.$router.push({path: `/work/start`});
            this.$router.go(-1);
            this.btnLoading = false;
          } else {
            this.$message.error(data.msg || '提交失败');
            Loading();
            this.btnLoading = false;
          }
        });
      },
      handleWitch() {
        getUserInfo().then(res => {
          const user = res.data.data;
          this.form.taskUser = user.account;
        });

        getDetail(this.$route.params.drawingUploadId).then(res => {
          const result = res.data.data;
          this.form.drawingNumber = result.drawingNumber;
          this.form.drawingName = result.drawingName;
        })
      },
    }
  }
</script>
